package com.ruoyi.college.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.college.domain.SecondLevelSubject;
import com.ruoyi.college.service.ISecondLevelSubjectService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 二级学科管理Controller
 * 
 * @author ruoyi
 * @date 2025-07-31
 */
@RestController
@RequestMapping("/college/secondSubject")
public class SecondLevelSubjectController extends BaseController
{
    @Autowired
    private ISecondLevelSubjectService secondLevelSubjectService;

    /**
     * 查询二级学科管理列表
     */
   // @PreAuthorize("@ss.hasPermi('college:secondSubject:list')")
    @GetMapping("/list")
    public TableDataInfo list(SecondLevelSubject secondLevelSubject)
    {
        startPage();
        List<SecondLevelSubject> list = secondLevelSubjectService.selectSecondLevelSubjectList(secondLevelSubject);
        return getDataTable(list);
    }

    /**
     * 导出二级学科管理列表
     */
    @PreAuthorize("@ss.hasPermi('college:secondSubject:export')")
    @Log(title = "二级学科管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SecondLevelSubject secondLevelSubject)
    {
        List<SecondLevelSubject> list = secondLevelSubjectService.selectSecondLevelSubjectList(secondLevelSubject);
        ExcelUtil<SecondLevelSubject> util = new ExcelUtil<SecondLevelSubject>(SecondLevelSubject.class);
        util.exportExcel(response, list, "二级学科管理数据");
    }

    /**
     * 获取二级学科管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('college:secondSubject:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(secondLevelSubjectService.selectSecondLevelSubjectById(id));
    }

    /**
     * 新增二级学科管理
     */
    @PreAuthorize("@ss.hasPermi('college:secondSubject:add')")
    @Log(title = "二级学科管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SecondLevelSubject secondLevelSubject)
    {
        return toAjax(secondLevelSubjectService.insertSecondLevelSubject(secondLevelSubject));
    }

    /**
     * 修改二级学科管理
     */
    @PreAuthorize("@ss.hasPermi('college:secondSubject:edit')")
    @Log(title = "二级学科管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SecondLevelSubject secondLevelSubject)
    {
        return toAjax(secondLevelSubjectService.updateSecondLevelSubject(secondLevelSubject));
    }

    /**
     * 删除二级学科管理
     */
    @PreAuthorize("@ss.hasPermi('college:secondSubject:remove')")
    @Log(title = "二级学科管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(secondLevelSubjectService.deleteSecondLevelSubjectByIds(ids));
    }
    /**
     * 根据学院id查询二级学科
     */
    @GetMapping("/getSecondSubjectByCollegeId/{collegeId}")
    public AjaxResult getSecondSubjectByCollegeId(@PathVariable String collegeId)
        {
            SecondLevelSubject secondLevelSubject=new SecondLevelSubject();
            secondLevelSubject.setCollegeId(collegeId);
            List<SecondLevelSubject> list=secondLevelSubjectService.selectSecondLevelSubjectList(secondLevelSubject);
            return success(list);
        }
}
